package com.example.student.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.domain.Result;
import com.example.common.domain.pojo.Homework;
import com.example.common.domain.pojo.WrongBooks;
import com.example.student.domain.Dto.WrongBooksQuery;
import com.example.student.domain.Vo.WrongBooksVo;
import com.example.student.service.HomeworkService;
import com.example.student.service.WrongBooksService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@Api(value = "学生端接口", description = "学生历史练习，错题")
@RestController
@RefreshScope//时时刷新配置信息
@Slf4j  //日志  log.info("登录日志测试：");
@RequestMapping("/students")
@RequiredArgsConstructor
public class AgeQuestionController {
    @Autowired
    private WrongBooksService wrongBooksService;
    @Autowired
    private HomeworkService homeworkService;

    @ApiOperation("添加错题")
    @PostMapping("/addWrongBooks")
    public Result<String> addWrongBooks(@RequestBody WrongBooks wrongBooks) {
        boolean save = wrongBooksService.save(wrongBooks);
        if (save) {
            return Result.success("添加成功");
        }
        return Result.error("添加失败");
    }


    @ApiOperation("删除错题")
    @PostMapping("/deleteWrongBooks/{id}")
    public Result<String> deleteWrongBooks(@PathVariable String id) {
        boolean delete = wrongBooksService.removeById(id);
        if (delete) {
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

    @ApiOperation("查询错题")
    @PostMapping("/getWrongBooks")
    public Result<Page<WrongBooksVo>> getWrongBooks(@RequestBody WrongBooksQuery query) {
        Page<WrongBooksVo> page = wrongBooksService.getWrongBooks(query);
        return Result.success(page);
    }

    @ApiOperation("查询题目是哪个作业的")
    @PostMapping("/getHomeworkId/{homeworkId}")
    public Result<Homework> getHomeworkId(@PathVariable String homeworkId) {
        Homework homework = homeworkService.getHomeworkByIdWithLogicalExpire(homeworkId);
        return Result.success(homework);
    }


}
